//
//  XLFormDescriptor.h
//  XLForm ( https://github.com/xmartlabs/XLForm )
//
//  Copyright (c) 2015 Xmartlabs ( http://xmartlabs.com )
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#import "Section.h"
#import "Row.h"
#import <Foundation/Foundation.h>

extern NSString * __nonnull const XLFormErrorDomain;
extern NSString * __nonnull const XLValidationStatusErrorKey;

typedef NS_OPTIONS(NSUInteger, XLFormRowNavigationOptions) {
    XLFormRowNavigationOptionNone                               = 0,
    XLFormRowNavigationOptionEnabled                            = 1 << 0,
    XLFormRowNavigationOptionStopDisableRow                     = 1 << 1,
    XLFormRowNavigationOptionSkipCanNotBecomeFirstResponderRow  = 1 << 2,
    XLFormRowNavigationOptionStopInlineRow                      = 1 << 3,
};

@class Section;
@class List;
@class Row;

@protocol FormDelegate <NSObject>

@required

-(void)sectionHasBeenRemoved:(Section *_Nonnull)formSection atIndex:(NSUInteger)index;
-(void)sectionHasBeenAdded:(Section *_Nonnull)formSection atIndex:(NSUInteger)index;

-(void)rowHasBeenAdded:(Row *_Nonnull)formRow atIndexPath:(NSIndexPath *_Nonnull)indexPath;
-(void)rowHasBeenRemoved:(Row *_Nonnull)formRow atIndexPath:(NSIndexPath *_Nonnull)indexPath;
@end



@interface Form : NSObject
@property(nonatomic, weak, nullable) List *list;
@property (readonly, nonatomic, nonnull) NSMutableArray * sections;
@property (weak, nullable) id<FormDelegate> delegate;

@property (nonatomic) XLFormRowNavigationOptions rowNavigationOptions;

+(nonnull instancetype)form;

-(void)addSection:(nonnull Section *)formSection;
-(void)addSection:(nonnull Section *)formSection atIndex:(NSUInteger)index;
-(void)addSection:(nonnull Section *)formSection afterSection:(nonnull Section *)afterSection;

-(void)removeSectionAtIndex:(NSUInteger)index;
-(void)removeSection:(nonnull Section *)formSection;

-(nullable Section *)sectionAtIndex:(NSUInteger)index;


-(void)addRow:(nonnull Row *)formRow beforeRow:(nonnull Row *)afterRow;
-(void)addRow:(nonnull Row *)formRow beforeRowTag:(nonnull NSString *)afterRowTag;
-(void)addRow:(nonnull Row *)formRow afterRow:(nonnull Row *)afterRow;
-(void)addRow:(nonnull Row *)formRow afterRowTag:(nonnull NSString *)afterRowTag;

-(void)removeRow:(nonnull Row *)formRow;
-(void)removeRowWithTag:(nonnull NSString *)tag;

-(nullable Row *)rowWithTag:(nonnull NSString *)tag;
-(nullable Row *)rowAtIndex:(nonnull NSIndexPath *)indexPath;

-(nullable NSIndexPath *)indexPathOfRow:(nonnull Row *)formRow;

-(nullable Row *)nextRowForRow:(nonnull Row *)currentRow;
-(nullable Row *)previousRowForRow:(nonnull Row *)currentRow;
@end
